var app = getApp();
Component({
    properties: {
        chouinfo : Object,
        params : Object,
        isPush : Boolean,
        info : Object,
    },
    data: {
        isshow : true,
        posterurl : '',
        isshowinfo : false,
        timeData : {},
        name : '',
        tel : '',
        address : '',
    },
    options : {
        addGlobalClass : true,
    },
    created(){

    },
    methods: {
        onshowinfo(){
            this.setData({
                isshowinfo : !this.data.isshowinfo
            })
        },
        onChangetime(e){
            this.setData({
                timeData: e.detail,
            });
        },
        showp(){
            this.upprize();
        },
        endchoufn(){
            var self = this;
            app.com.confirm('确定开奖吗？',function(){
                self.endchou();
            })
        },
        endchou(){
            var self = this;
            if(this.data.chouinfo.status == 2 || !this.data.isPush){
                return false;
            }
            var postdata = {
                op : 'openchou',
                liveid :  self.data.info.id,
                cid : self.data.chouinfo.id,
            };
            app.com.http('live','POST',postdata,0,true,'','',function(res){
                if ( !res.data.errno && res.data.errno !== undefined ) {
                    self.setData({
                        'chouinfo.status' : 2,
                    })
                    if(res.data.data.mess){
                        app.com.sendGo(res.data.data.mess,res.data.data.channel);
                    }
                }else{
                    app.com.alert(res.data.message);
                }
            });
        },
        copy(e){
            app.com.copy(e);
        },
        startchou(){
            var self = this;
            var postdata = {
                op : 'startchou',
                liveid :  self.data.info.id,
                cid : self.data.chouinfo.id,
            };
            app.com.http('live','POST',postdata,0,true,'','',function(res){
                if ( !res.data.errno && res.data.errno !== undefined ) {
                    self.setData({
                        'chouinfo.status' : 1,
                        'chouinfo.endtime' : res.data.data.endtime,
                    })
                    if(res.data.data.mess){
                        app.com.sendGo(res.data.data.mess,res.data.data.channel);
                    }
                }else{
                    app.com.alert(res.data.message);
                }
            });
        },
        upprize(){
            var self = this;
            var postdata = {
                op : 'getprize',
                liveid :  self.data.info.id,
            };
            app.com.http('live','POST',postdata,0,true,'','',function(res){
                if ( !res.data.errno && res.data.errno !== undefined ) {
                    self.setData({
                        'chouinfo' : res.data.data.chouinfo,
                        isshowinfo : true,
                    })
                    app.com.toast('已更新开奖信息');
                }else{
                    app.com.alert(res.data.message);
                }
            });
        },
        location : function( e ){
            app.com.location( e );
        },
        onshowaddress(){
            this.setData({
                isshowaddress : !this.data.isshowaddress
            })
        },
        onChange(e){
            var type = e.currentTarget.dataset.type;
            this.setData({
                [type] : e.detail
            })
        },
        subaddress(){
            
            var self = this;
            var postdata = {
                op : 'settel',
                logid :  self.data.chouinfo.logid,
                name : self.data.name,
                tel : self.data.tel,
                address : self.data.address,
            };
            app.com.confirm('提交后无法修改，确定提交吗？',function(){
                app.com.http('live','POST',postdata,0,true,'','',function(res){
                    if ( !res.data.errno && res.data.errno !== undefined ) {
                        self.setData({
                            'chouinfo.name' : postdata.name,
                            'chouinfo.tel' : postdata.tel,
                            'chouinfo.address' : postdata.address,
                            isshowaddress : false,
                        })
                    }
                    app.com.alert(res.data.message);
                });
            })
        }
    }

})